package sk.fiit.lulco.grafy;

import java.util.Collections;

/**
 * class for Brelaz algorithm
 */
public class BrelazAlgorithm extends AbstractAlgorithm {
	
	private static final VertexBrelazComparator comparator = new VertexBrelazComparator(HEALConstants.SortType.DESC);
	
	public Graph color(Graph graph) {
		while (!graph.isColored()) {
			Collections.sort(graph.getVertices(), comparator);
			Vertex vertex = graph.getVertices().get(0);
			int minimalColor = graph.getMinimalFreeColor(vertex.getNeighbours(), null);
			//System.out.println("minimal color " + minimalColor);
			vertex.setColor(minimalColor);
		}
		return graph;
	}
}